package com.hsxxherp.simplify.framework.utils.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

// 自定义脱敏序列化器
public class DesensitizedSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value != null && value.length() > 4) {
            // 简单示例：保留前两位和后两位，中间用 * 替换
            String desensitized = value.substring(0, 2) + "****" + value.substring(value.length() - 2);
            gen.writeString(desensitized);
        } else {
            gen.writeString(value);
        }
    }
}
